package BuyBot;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Vector;

class StoreCatalogImpl extends UnicastRemoteObject implements StoreCatalog {
	private static final long serialVersionUID = -5995218968397664902L;

	private Vector<OnlineStore> onlinestores; // a lista das lojas ja cadastradas

	/** Construtor 
	 * @throws RemoteException */
	public StoreCatalogImpl() throws RemoteException {
		super();
		this.onlinestores = new Vector<OnlineStore>();
	}

	@Override
	public void register(OnlineStore store)throws RemoteException {
		this.onlinestores.add(store);
		System.out.println("Registered new OnlineStore of name: " + store.getName());
	}

	@Override
	public Vector<OnlineStore> getOnlineStores()throws RemoteException {
		this.onlinestores.trimToSize();
		return this.onlinestores;
	}

	public static void main(String[] args)throws Exception {
		if (System.getSecurityManager() == null) {
            System.setSecurityManager (new RMISecurityManager());
		}
		
		try {
			StoreCatalog storeCatalog = new StoreCatalogImpl();
			Naming.rebind("Catalog", storeCatalog);
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
	}

	@Override
	public int returnNumber(int i) throws RemoteException {
		// TODO Auto-generated method stub
		return i;
	}
}
